package org.myabstract.graph.model.tests;

import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.List;

import org.junit.Before;
import org.junit.Test;
import org.myabstract.graph.model.IArc;
import org.myabstract.graph.model.INodeType;
import org.myabstract.graph.model.Node;
import org.myabstract.graph.model.Reference;

public class ReferenceTests {

	private Reference<INodeType, INodeType> ref;
	private Node node1;
	private Node node2;

	@Before
	public void setUp() {
		node1 = new Node<INodeType>(new Mock1NodeType());
		node2 = new Node<INodeType>(new Mock2NodeType());
		try {
			ref = new Reference<INodeType, INodeType>(node1, node2);
		} catch (Exception e) {
			e.printStackTrace();
			System.err.println(e.toString());
		}
	}
 
	@Test
	public void containsPass() {
		assertTrue(ref.contains(Mock2NodeType.class));
	}

	@Test
	public void containsPass2() {
		assertTrue(ref.contains(Mock1NodeType.class));
	}

	@Test
	public void containsNull() {
		assertTrue(ref.contains(null) == false);
	}

	@Test
	public void containsFalse() {
		assertTrue(ref.contains(MockNodeType.class) == false);
	}

	// @Test
	// public void checkTestTrue() {
	// assertTrue(ref.mockCheck(node1, node2));
	// }
	//
	// @Test
	// public void checkTestFalse() {
	// assertTrue(ref.mockCheck(node1, node1) == false);
	// }

	@Test(expected = java.lang.Exception.class)
	public void referenceConstructorIdenticalElements() throws Exception {
		ref = new Reference<INodeType, INodeType>(node1, node1);

	}

	@Test
	public void addArcTest() {
		IArc arc = new Mock1Arc();
		ref.addArc(arc);
		assertTrue(ref.getArcList().size() == 1);
		assertEquals(arc, ref.getArcList().get(0));
	}

	@Test
	public void addArcNull() {
		assertTrue(ref.addArc(null) == false);
	}

	@Test
	public void getNodeTest1() {
		assertEquals(node1, ref.getNode(node2));
	}

	@Test
	public void getNodeTest2() {
		assertEquals(node2, ref.getNode(node1));
	}
	@Test
	public void getNodesTest(){
		List res= ref.getNodes();
		List exp=new ArrayList<Node<INodeType>>();
		exp.add(node2);
		exp.add(node1);
		assertEquals(exp, res);
	}

}
